找传奇、传世资源到传世资源站!

android 线型布局管理器(入门级)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboardpackage com.example.radio;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.CheckBox;import android.widget.LinearLayout;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;public class MainActivity extends Activity {private RadioGroup radioContainer;private LinearLayout checkContainer;TextView tv1;TextView tv2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); radioContainer=(RadioGroup)(findViewById(R.id.radioContainer));checkContainer=(LinearLayout)(findViewById(R.id.checkContainer));tv1=(TextView)findViewById(R.id.txtView);tv2=(TextView)findViewById(R.id.birthView); } public void buttonClick(View view){Log.i("Button","Button Clicked");} public void btnDisplaySelected(View view){String radioText="";for(int i=0;i<radioContainer.getChildCount();i ){View c=radioContainer.getChildAt(i);if(c instanceof RadioButton){RadioButton radio=(RadioButton)c;if(radio.isChecked()){radioText=radio.getText().toString();}}}tv1.setText(radioText);Log.i("Radio","Radio Selected is" radioText);String checkText="";for(int i=0;i<checkContainer.getChildCount();i ){View c=checkContainer.getChildAt(i);if(c instanceof CheckBox){CheckBox check=(CheckBox)c;if(check.isChecked()){checkText =check.getText().toString() ";";}}}tv2.setText(checkText);Log.i("Check","Check Selected is" checkText);} @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复